﻿using Furion;
using Furion.RemoteRequest.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace iemtm.WeChat.Core.Util
{
    /// <summary>
    /// Tcp通讯
    /// </summary>
    public class TcpCommunication
    {
        public const string GetSenCMDWrite = "SendCMDWrite?";
        public const string GetSenCMDRead = "SendCMDRead?";
        public const string GetGenOnline = "GenOnline";
        public const string GetRealMonitor = "realMonitor?";//实时监控

        private static string TcpWebBaseUri = App.Configuration["AppProgramConfig:TcpWebBaseUri"];
        //private static string TcpWebBaseUri ="AppConfig:TcpWebBaseUri";

        /// <summary>
        ///     向Tcp发送-需要写入硬件命令 
        /// </summary>
        /// <param name="dtuCmd"></param>
        /// <param name="DTUID"></param>
        /// <param name="responseTimeout"></param>
        /// <returns></returns>
        public static async Task<string> WritePara(string dtuCmd, string DTUID, int responseTimeout)
        {

            string DataFrom = string.Format("dtuCmd={0}&DTUID={1}&responseTimeout={2}", dtuCmd, DTUID, responseTimeout);
            string serviceUrl = string.Format("{0}/{1}", TcpWebBaseUri+ GetSenCMDWrite, DataFrom);
            var response=await serviceUrl.GetAsync();
            string resultV = response.Content.ReadAsStringAsync().Result;
            return resultV;
        }

        /// <summary>
        ///     向Tcp发送-需要查询硬件命令 
        /// </summary>
        /// <param name="dtuCmd"></param>
        /// <param name="DTUID"></param>
        /// <param name="responseTimeout"></param>
        /// <returns></returns>
        public static async Task<string> ReadParas(string dtuCmd, string DTUID, int responseTimeout)
        {

            string DataFrom = string.Format("dtuCmd={0}&DTUID={1}&responseTimeout={2}", dtuCmd, DTUID, responseTimeout);
            string serviceUrl = string.Format("{0}/{1}", TcpWebBaseUri+ GetSenCMDRead, DataFrom);
            var response = await serviceUrl.GetAsync();
            string resultV = response.Content.ReadAsStringAsync().Result;
            return resultV;

        }
        



        /// <summary>
        /// 实时监控-发送查询状态的命令
        /// </summary>
        /// <param name="DTUID"></param>
        /// <returns></returns>
        public static async Task<string> realMonitor(string DTUID)
        {

            string DataFrom = string.Format("DTUID={0}", DTUID);
            string serviceUrl = string.Format("{0}/{1}", TcpWebBaseUri+ GetRealMonitor, DataFrom);
            var response = await serviceUrl.GetAsync();
            string resultV = response.Content.ReadAsStringAsync().Result;
            return resultV;

        }





        /// <summary>
        /// 获取 所有在线油机
        /// </summary>
        /// <returns></returns>

        public static async Task<string> GenOnline()
        {

           
            string serviceUrl = string.Format("{0}/{1}", TcpWebBaseUri+ GetGenOnline, "");
            var response = await serviceUrl.GetAsync();
            string resultV = response.Content.ReadAsStringAsync().Result;
            return resultV;
        }

    }



    public class CodeValuePair
    {
        protected string _code = "";

        protected string _value = "";

        public string code
        {
            get
            {
                return _code;
            }
            set
            {
                _code = value;
            }
        }

        public string value
        {
            get
            {
                return _value;
            }
            set
            {
                _value = value;
            }
        }
    }
}
